<?php


namespace app\home\model\dealer;
use app\home\model\BaseModel;
class Dealer extends BaseModel
{
    protected $append=['day'];
    protected $autoWriteTimestamp='datetime';
    public $dealerMoney=[];

    public function getDayAttr($val){
        $create_time=$this->getAttr("create_time");
       return ceil((time()-strtotime($create_time))/86400);
    }
    /**
     * 查询字段值
     * @param $field
     * @param $value
     * @param $val
     * @return mixed
     */
    public static function getFieldVal($field,$value,$val){
        return self::where($field,$value)->value($val);
    }
    /**
     * @param $val
     * @return string
     */
    public function getPhoneAttr($val){
        return num_secret($val);
    }

    /**通过代理编码获取到代理信息
     * @param string $dealerCode
     * @return array|false|\PDOStatement|string|\think\Model
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public  function goDealerCode($dealerCode=''){
        if(empty($dealerCode)) return [];
        $result=parent::getFind(["dealer_code"=>$dealerCode]);
        return $result;
    }
}